<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>shadow</title>
</head>
<body>
  <div>
    <p>hello world</p>
    <div id="shadow"></div>
  </div>
  <script>
    let shadowDOM = document.getElementById('shadow').attachShadow({mode:'closed'}) // 外界无法访问 shadow dom 
    let pElm = document.createElement('p')
    pElm.innerHTML = 'Hello hello'
    let styleElm = document.createElement('style')
    styleElm.textContent = `
      p{color:red}
    `
    shadowDOM.appendChild(styleElm)
    shadowDOM.appendChild(pElm)
    // document.body.appendChild(pElm)
  </script>
  
</body>
</html>